<template>
  <a-spin :spinning="spinning != 0">
    <a-form :form="form"
            layout="horizontal"
            :hideRequiredMark="false"
            style="">
      <a-row class="grid-row">

        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="基础包路径" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入基础包路径"
              type="text"
              v-decorator="['applicationPackage', validatorRules.applicationPackage]"
            />
          </a-form-item>
        </a-col>

        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="组件名" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入组件名"
              type="text"
              v-decorator="['serviceName', validatorRules.serviceName]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="端口号" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入端口号"
              type="text"
              v-decorator="['servicePort', validatorRules.servicePort]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="数据库地址" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入数据库地址"
              type="text"
              v-decorator="['dbUrl', validatorRules.dbUrl]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="数据库用户名" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入数据库用户名"
              type="text"
              v-decorator="['dbUserName', validatorRules.dbUserName]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="数据库密码" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入数据库密码"
              type="text"
              v-decorator="['dbPassword', validatorRules.dbPassword]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="数据库驱动类" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入数据库驱动类"
              type="text"
              v-decorator="['driverClassName', validatorRules.driverClassName]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="redis地址" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入redis地址"
              type="text"
              v-decorator="['redisUrl', validatorRules.redisUrl]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="redis密码" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入redis密码"
              type="text"
              v-decorator="['redisPassword', validatorRules.redisPassword]"
            />
          </a-form-item>
        </a-col>
        <a-col v-bind="colLayout2.cols" class="grid-col">
          <a-form-item label="redis端口" :label-col="colLayout2.labelCol" :wrapper-col="colLayout2.wrapperCol">
            <a-input
              :disabled="false"
              placeholder="请输入redis端口"
              type="text"
              v-decorator="['redisPort', validatorRules.redisPort]"
            />
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
  </a-spin>
</template>

<script>

  import {FormMixin} from '@/mixins/FormMixin'
  import {GardLayoutMixin} from '@/mixins/GardLayoutMixin'
  import UploadImg from '@/views/eform/modules/designer/packages/UploadImg'
  import UploadFile from '@/views/eform/modules/designer/packages/UploadFile'
  import YchSelectUser from '@/components/ych/ych-user/YchSelectUser'
  import YchSelectDepart from '@/components/ych/ych-org/YchSelectDepart'
  import ViewSelectTag from '@/views/eform/select/viewSelect/ViewSelectTag'
  import YchConstant from "@/api/YchConstant";
  import { downloadFile,downFile } from '@/api/manage'

  export default {
    name: "BootProjectFormModal",
    mixins: [FormMixin, GardLayoutMixin],
    components: {
      UploadImg,
      UploadFile,
      YchSelectUser,
      YchSelectDepart,
      ViewSelectTag,
    },
    data() {
      return {
        validatorRules: {
          applicationPackage: {
            initialValue:'com.yuncheng',
            rules: [{"required": true, "message": "包路径 必填"}]
          },
          serviceName: {
            initialValue:'demo',
            rules: [{"required": true, "message": "服务名 必填"}]
          },
          servicePort: {
            initialValue:'30001',
            rules: [{"required": true, "message": "服务端口号 必填"}]
          },
          dbUrl: {
            initialValue:'jdbc:mysql://127.0.0.1:3306/yuncheng?characterEncoding=UTF-8&useUnicode=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai',
            rules: [{"required": true, "message": "数据库地址 必填"}]
          },
          dbUserName: {
            initialValue:'root',
            rules: [{"required": true, "message": "数据库用户名 必填"}]
          },
          dbPassword: {
            initialValue:'root',
            rules: [{"required": true, "message": "数据库密码 必填"}]
          },
          driverClassName: {
            initialValue:'com.mysql.cj.jdbc.Driver',
            rules: [{"required": true, "message": "数据库驱动类 必填"}]
          },
          redisUrl: {
            initialValue:'127.0.0.1',
            rules: [{"required": true, "message": "redis_url 必填"}]
          },
          redisPassword: {
            rules: []
          },
          redisPort: {
            initialValue:'6379',
            rules: [{"required": true, "message": "redis_port 必填"}]
          },
        },
        dictConfig: {},
        optionConfig: {},
        url: {
          queryById: '/springbootdemo/springbootproject/queryById',
          add: "/springbootdemo/springbootproject/add",
          edit: "/springbootdemo/springbootproject/edit",
          genSpringBootProject: YchConstant.PREFIX_EFORM + '/generator/codeGeneratorController/genSpringBootProject',
        },
        uploadImgOptions: {},
        uploadFileOptions: {},
        checkBoxOptions: {},
      }
    },
    methods: {
      save () {
        this.form.validateFields(async (err, values) => {
          if (!err) {
            downloadFile(this.url.genSpringBootProject,values.serviceName+'.zip',values,'POST').finally(() => {
              this.$emit('refreshParent')
            })
          }
        })

      },
    },
  }
</script>
